package com.example.admin.system.config;

import org.apache.tomcat.websocket.AuthenticationException;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;

/**
 * autho token interceptor.
 *
 * @author liucheng
 * @since 0.1 2021-07-31 11:56 PM
 **/
@Component
public class AuthTokenInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (!Objects.equals(request.getHeader(HttpHeaders.AUTHORIZATION), "123")) {
            throw new AuthenticationException("token不正确");
        }
        return true;
    }
}
